#include "Bitmap3f.h"

Bitmap3f::Bitmap3f() {
    h = 0;
    w = 0;
    data = 0;
}

Bitmap3f::Bitmap3f(FIBITMAP* source) {
    setData(source);
}

Bitmap3f::~Bitmap3f() {
    delete[] data;
}

void Bitmap3f::setData(FIBITMAP* source) {
    h = FreeImage_GetHeight(source);
    w = FreeImage_GetWidth(source);

    data = new Color3f[h*w];
    
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) {
            RGBQUAD rawColor;
            FreeImage_GetPixelColor(source, j, i, &rawColor);
            at(j, i) = Color3f(rawColor.rgbRed / 255.0f, rawColor.rgbGreen / 255.0f, rawColor.rgbBlue / 255.0f);
        }
}

void Bitmap3f::deleteData() {
    delete[] data;
    data = 0;
}

Color3f& Bitmap3f::at(int x, int y) const {
    return data[y*w+x];
}